package com.example.mybatis_generation.controller;


import com.alibaba.fastjson.JSONObject;
import com.example.mybatis_generation.domain.JsonData;
import com.example.mybatis_generation.service.impl.JsonDataServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author qiDing
 * @since 2021-12-14
 */
@RestController
@RequestMapping("/jsonData")
@AllArgsConstructor
public class JsonDataController {

    private final JsonDataServiceImpl jsonDataService;

    @GetMapping("/test")
    public JsonData test() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", 2);
        ArrayList<String> arr = new ArrayList<>();
        arr.add("a");
        arr.add("ab");
        arr.add("abc");
        jsonObject.put("arr",arr);
        boolean save = jsonDataService.save(new JsonData().setJsonData(jsonObject.toJSONString()));
        System.out.println(save);
        JsonData byId = jsonDataService.getById(1);
        System.out.println(byId);
        return byId;
    }
}

